package qnb._common.easyui;



import qnb._common.ConditionTool;
import qnb._common._ModuleKey;
import qnb._common.tools.StringTool;

public class EasyuiPageVO {
	private int page = 1;
	private int rows = 10;	//每行显示行数
	private String sort;
	private String order = "DESC"; // 排序方式
	private String whereSql = "1=1"; // 动态拼接SQL: where

	public int getPage() {
		return page;
	}

	public int getPageSQL() {
		return (page - 1) * rows;
	}

	/**
	 * 查检参数，防注入
	 * 
	 * @return
	 */
	public boolean isSqlError() {
		if (sqlError(this.sort)) {
			return true;
		}
		if (sqlError(this.order)) {
			return true;
		}
		return false;
	}

	/**
	 * sql注入过滤
	 * 
	 * @param param
	 * @return boolean
	 */
	private boolean sqlError(String param) {
//		if (null != param && param.length() > 0 && (param.indexOf("'") != -1 || param.indexOf("-") != 1)) {
//			return true;
//		}
		return false;
	}

	public String getOrderbySQL() {
		if (null == sort || sort.isEmpty()) {
			return null;
		}
		return StringTool.formatStringNameToSqlName(this.sort) + " " + order;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public String getWhereSql() {
		return whereSql==null?"":whereSql;
	}
	public String getWhereSql(_ModuleKey key) {
		return whereSql==null?"":ConditionTool.engineToSQLCondition(key,this.whereSql);
	}
	public void setWhereSql(String whereSql) {
		this.whereSql = whereSql;
	}

	public Integer getStart() {
		return ((this.getPage() - 1) * this.getRows());
	}
}
